<?
$put_scr = false;

// plot 001 instead of 1.
function number_pad($number,$n) {
	return str_pad((int) $number,$n,"0",STR_PAD_LEFT);
}


// give the current time
function compute_time(){
	$mtime = microtime();
	$mtime = explode(" ",$mtime);
	$mtime = $mtime[1] + $mtime[0];
	return $mtime;
}


// load a tab separated valu file
function load_tabbed_file($filepath, $load_keys=false)
{
    $array = array();
 
    if (!file_exists($filepath)){ return $array; }
    $content = file($filepath);
 
    for ($x=0; $x < count($content); $x++){
        if (trim($content[$x]) != ''){
            $line = explode("\t", trim($content[$x]));
            if ($load_keys){
                $key = array_shift($line);
                $array[$key] = $line;
            }
            else { $array[] = $line; }
        }
    }
    return $array;
}


// get the IP of the user
function get_ip(){
	$put_scr = false;

	if (getenv('HTTP_X_FORWARDED_FOR')) {
	    $pipaddress = getenv('HTTP_X_FORWARDED_FOR');
	    $ipaddress = getenv('REMOTE_ADDR');
	//if ($put_scr==true) echo "Your Proxy IPaddress is : ".$pipaddress. "(via $ipaddress)" ;
	} 
	else {
	    $ipaddress = getenv('REMOTE_ADDR');
	    $pipaddress = "";
	    //if ($put_scr==true) echo "Your IP address is : $ipaddress";
	}
	$out_ip[0]=$ipaddress;
	$out_ip[1]=$pipaddress;
	return $out_ip;
}


//serialize an array
function serializeme($me){
	$output="";
	while(list($key,$value)=each($me)){
		$output.=$key."=".$value;
		$output.="&";
		}
	$output = substr($output,0,strlen($output)-1);
	//$output .= "\"";
	return $output;	
	}

?>
